<?php
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');

class LinkController extends AppController {
   

    public function beforeFilter(){
		parent::beforeFilter();
		// tutte le azioni di questo controller possono essere eseguite
		 // $this->Auth->allow("index","edit","save","delete","add");
    }
    
    
    
    public function index(){
        $this->set("links",$this->Link->find("all"));
    }
    
    public function edit($id){
	    $this->layout="admin";
        $this->loadModel("Bookmaker");
        $bookmaker_list = $this->Bookmaker->find("all",array("conditions" => array("Bookmaker.deleted" => 0)));
        
        $linkmodel = $this->Link->read(null,$id);
        
        $this->set("link",$linkmodel);
        $this->set("bookmaker_list",$bookmaker_list);
        
    }
    
    //ATTENZIONE: **** gli passo in caso il bookmaker parent se ce l'ho!!****
    public function add($idBookmaker=null){
	    $this->layout="admin";
        $this->loadModel("Bookmaker");        
        $bookmaker_list = $this->Bookmaker->find("all",array("conditions" => array("Bookmaker.deleted" => 0)));
        $this->Bookmaker->recursive = -1;
        $bookmodel = $this->Bookmaker->read(null,$idBookmaker);
        $this->set("bm",$bookmodel);
        $this->set("bookmaker_list",$bookmaker_list);
    }
    
    public function save($id=null){
        $this->Link->set($this->request->data);
       // pr($this->request->data);die;
        $this->Link->save();
        
        $this->Session->setFlash("Link aggiornata con successo");
        $this->redirect("/Link/edit/".$this->Link->id);
        
    }
    
    public function delete($value)
    {
        $this->Link->read(null,$value);
        $this->Link->delete();
              
        $this->Session->setFlash("Link eliminato con successo!");
        $this->redirect("/Link/index");
    }

}

?>